<template>
	<view class="home">
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" autoplay :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- 导航栏区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品区域 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<goods-list :goods="goods"></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list.vue'
	export default {
		data() {
			return {
				swipers:[],
				goods:[],
				navs:[
					{
						'icon':'iconfont icon-ziyuan',
						'title':'Fingle',
						'path':'/pages/goods/goods'
					},
					{
						'icon':'iconfont icon-guanyuwomen',
						'title':'联系我们',
						'path':'/pages/contact/contact'
					},
					{
						'icon':'iconfont icon-tupian',
						'title':'社区图片',
						'path':'/pages/pics/pics'
					},
					{
						'icon':'iconfont icon-shipin',
						'title':'学习视频',
						'path':'/pages/videos/videos'
					},
				]
			}
		},
		onLoad() {
			this.getSwipers(),
			this.getHotGoods()
		},
		components:{
			"goods-list":goodsList,
		},
		methods: {
			//获取轮播图数据
			async getSwipers(){
				const res = await this.$myrequest({
					url:'/api/getlunbo'
				})
				this.swipers = res.data.message
			},
			//获取商品列表数据
			async getHotGoods(){
				const res = await this.$myrequest({
					url:'/api/getgoods?pageindex=1',
				})
				res.data.message.map((item)=>{
					item.img_url ='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fk.zol-img.com.cn%2Fsjbbs%2F6319%2Fa6318644_s.jpg&refer=http%3A%2F%2Fk.zol-img.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619345904&t=dad8736a9b8b687aa936cc7b4aa630c9'
				})
				this.goods = [...this.goods,...res.data.message]
			},
			//导航跳转
			navItemClick(url){
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style lang="scss">
.home{
	swiper{
		width: 750rpx;
		height: 380rpx;
		image{
			height: 100%;
			width: 100%;
		}
	}
	.nav{
		display: flex;
		.nav_item{
			flex: 1;
			text-align: center;
			text{
				font-size: 30rpx;
			}
			view{
				flex: 1;
				width: 120rpx;
				height: 120rpx;
				background-color: $market-color;
				border-radius: 60rpx;
				margin: 10rpx 0rpx 10rpx 35rpx;
				line-height: 120rpx;
				color: #FFFFFF;
				font-size: 60rpx;
			}
			.icon-tupian{
				font-size: 50rpx;
			}
		}
	}
	.hot_goods{
		background-color: #eee;
		overflow: hidden;
		margin-top: 5rpx;
		.tit{
			height: 50rpx;
			color: $market-color;
			text-align: center;
			letter-spacing: 20rpx;
			background: #fff;
			margin: 7rpx 0;
		}
	}
}

</style>
